<template>
    <view class="content">
        <view class="nav">
            <view class="nav-i" :class="{active : type == 1}" @click="chooseNav(1)">已接单</view>
			<view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">已拒绝</view>
            <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">运输中</view>
            <view class="nav-i" :class="{active : type == 4}" @click="chooseNav(4)">已完成</view>
        </view>
        
        <view class="box" v-for="(item, index) in list" :key="index" @click="toDetails(item)">
            <template v-if="type == 1 || type == 2">
                <view class="item">
                    <view class="left">运输线路</view>
                    <view class="right">{{item.line}}</view>
					<!-- status 1审核中 3同意 4驳回 -->
					<view class="text-red" v-if="type == 1 && item.mode == 2 && item.status == 1">审核中</view>
					<view class="text-red" v-if="type == 1 && item.mode == 2 && item.status == 3">同意</view>
					<view class="text-red" v-if="type == 1 && item.mode == 2 && item.status == 4">驳回</view>
                </view>
                <view class="item">
                    <view class="left">始发地</view>
                    <view class="right">{{item.origin}}</view>
                </view>
                <view class="item">
                    <view class="left">目的地</view>
                    <view class="right">{{item.destination}}</view>
                </view>
                <view class="item">
                    <view class="left">装车地点</view>
                    <view class="right">{{item.loading_site}}</view>
                </view>
                <view class="item" v-if="item.vehicle">
                    <view class="left">车辆类型</view>
                    <view class="right">{{item.vehicle}}</view>
                </view>
                <view class="item" v-if="item.length">
                    <view class="left">车长要求</view>
                    <view class="right">{{item.length}}</view>
                </view>
                <view class="item" v-if="item.load">
                    <view class="left">载重要求</view>
                    <view class="right">{{item.load}}</view>
                </view>
                <view class="item">
                    <view class="left">发车时间</view>
                    <view class="right">{{item.start_date}}</view>
                </view>
                <view class="item">
                    <view class="left">预计到达时间</view>
                    <view class="right">{{item.end_date}}</view>
                </view>
                <view class="item">
                    <view class="left">租赁费用</view>
                    <view class="right">{{item.costs}}元</view>
                </view>
            </template>
            
            <template v-if="type == 3 || type == 4">
                <view class="item">
                    <view class="left">运输线路</view>
                    <view class="right">{{item.line}}</view>
                </view>
                <view class="item">
                    <view class="left">运单编号</view>
                    <view class="right">{{item.out_trade_no}}</view>
                </view>
                <view class="item">
                    <view class="left">货物类型</view>
                    <view class="right">{{item.goods_type}}</view>
                </view>
                <view class="item">
                    <view class="left">总件数</view>
                    <view class="right">{{item.all_num}}件</view>
                </view>
                <view class="item">
                    <view class="left">总重量</view>
                    <view class="right">{{item.all_weight}}斤</view>
                </view>
                <view class="item">
                    <view class="left">发车时间</view>
                    <view class="right">{{item.start_date}}</view>
                </view>
                
                <view class="btns" v-if="type == 3">
                    <view class="btn1" @click.stop="confirm(item)">确认到达</view>
                </view>
            </template>
        </view>
		
		<view style="height: 94rpx;padding-top: 30rpx;">
		    <u-loadmore :status="status" v-if="status != 'loadmore'" />
		</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                type: 1,
				status: 'loadmore', //是否显示没有更多了
				page: 1,
				list: [],
            };
        },
        onLoad(option) {
            this.type = option.type
        },
		onShow() {
		    this.list = []
		    this.page = 1
		    this.status = 'loadmore'
		    this.getList()
		},
		onReachBottom() {
			if(this.page == 1){return}
			this.getList()
		},
        methods: {
			toDetails(item) {
				// status 1审核中 3同意 4驳回
				this.$gTo(`/pagesA/order/details?id=${item.id}&type=${this.type}`)
			},
			
			// 确认到达
			confirm(item) {
				let lat = '', log = ''
				this.$getLocation((latitude,longitude) => {
				    console.log('000',latitude, longitude)
				    lat = latitude
					log = longitude
					
					if (lat) {
						this.$confirm('是否确认到达？', ()=> {
							this.$ajax('confirm_arrival', {
								user_token: this.$getSync('userToken'),
								order_id: item.id,//运单id
								longitude: log,//经度
								latitude: lat,//纬度
							}).then(ret => {
								if (ret.success == 1000) {
									this.$toast('提交成功')
									setTimeout(() => {
										this.list = []
										this.page = 1
										this.status = 'loadmore'
										this.getList()
									}, 500)
								} else {
									this.$toast(ret.msg);
								}
							});
						})
					} else {
						uni.showModal({
						    title: '温馨提示',
						    content: '确认到达需要获取您当前位置，检测到您没打开定位权限，是否去设置打开？',
						    success: function (res) {
						        if (res.confirm) {
						            wx.openSetting()
						        }
						    }
						})
					}
				})
				
			},
			
            chooseNav(num) {
				if (this.type == num) return
                this.type = num
				this.list = []
				this.page = 1
				this.status = 'loadmore'
				this.getList()
            },
			
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('driver_waybill', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
					status: this.type,//1已接单 2已拒绝 3运输中 4已完成
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.orders && ret.detail.orders.length > 0) {
            				this.list = this.list.concat(ret.detail.orders);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    
    page{
        background-color: #eef1f6;
    }
    .content{
        padding-bottom: 50rpx;
    }
    .nav{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx 0;
        border-bottom: 2rpx solid #ebebeb;
        background-color: #fff;
    }
    .nav-i{
        width: calc(100vw / 4);
        font-size: 28rpx;
        text-align: center;
        position: relative;
    }
    .ord-num{
        font-size: 20rpx;
        line-height: 1;
        color: #fff;
        padding: 5rpx 8rpx;
        background-color: #fa3c07;
        border-radius: 50%;
        position: absolute;
        right: -5rpx;
        top: -20rpx;
    }
    .ord-num2{
        font-size: 20rpx;
        line-height: 1;
        color: #fff;
        padding: 6rpx 4.5rpx;
        background-color: #fa3c07;
        border-radius: 50%;
        position: absolute;
        right: -5rpx;
        top: -20rpx;
    }
    .active{
        color: #004580;
        font-weight: bold;
        position: relative;
    }
    .active::after{
        display: block;
        content: '';
        width: 32rpx;
        height: 8rpx;
        background-color: #004580;
        position: absolute;
        bottom: -30rpx;
        left: 50%;
        transform: translateX(-50%);
    }
    
    .box{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 40rpx 30rpx 30rpx;
        margin: 16rpx 20rpx 0;
    }
    .top{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 10rpx;
    }
    .left{
        width: 190rpx;
        color: #656565;
    }
    .right{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
    }
    .o-sta{
        font-size: 24rpx;
        color: #ff602c;
        padding-bottom: 10rpx;
        padding-left: 10rpx;
    }
    .o-sta1{
        font-size: 24rpx;
        color: #ff602c;
        padding: 7rpx 15rpx;
        background-color: #fff1ec;
        border-radius: 10rpx;
        margin-left: 10rpx;
        margin-bottom: 10rpx;
    }
    .o-sta2{
        font-size: 24rpx;
        color: #0075ff;
        padding: 7rpx 15rpx;
        background-color: #ebf4fe;
        border-radius: 10rpx;
        margin-left: 10rpx;
        margin-bottom: 10rpx;
    }
    .price{
        font-size: 26rpx;
        color: #ff602c;
    }
    .price-num{
        font-size: 38rpx;
    }
    .btns{
        padding-top: 10rpx;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        color: #fff;
    }
    .btn1{
        padding: 15rpx 25rpx;
        background-color: #004580;
        border-radius: 50rpx;
        margin-left: 20rpx;
    }
    .btn2{
        padding: 15rpx 25rpx;
        background-color: #9aafc2;
        border-radius: 50rpx;
        margin-left: 20rpx;
    }
    .btn3{
        padding: 15rpx 25rpx;
        background-color: #fff;
        border-radius: 50rpx;
        margin-left: 20rpx;
        color: #004580;
        border: 2rpx solid #004580;
        box-sizing: border-box;
    }
    
    
    .popup{
        padding: 30rpx;
    }
    .pop-title{
        font-size: 34rpx;
        font-weight: bold;
        text-align: center;
        padding-bottom: 40rpx;
    }
    .pop-tip{
        font-size: 24rpx;
        color: #fe6a00;
        padding-top: 20rpx;
        padding-bottom: 50rpx;
    }
    .t-inp{
        padding: 20rpx;
        background-color: #f5f5f5;
        border-radius: 10rpx;
        font-size: 26rpx;
        width: 100%;
        min-height: 220rpx;
    }
    .pop-btn{
        font-size: 30rpx;
        color: #fff;
        text-align: center;
        padding: 20rpx;
        background-color: #00457f;
        border-radius: 50rpx;
    }
    

</style>
